package com.mojian.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.mojian.mapper.PayOrderMapper;
import com.mojian.service.PaymentService;
import com.mojian.service.impl.PaymentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * 支付模块配置类
 * 用于解决Bean创建顺序和依赖问题
 */
@Configuration
public class PaymentBeanConfig {

    @Autowired(required = false)
    private PayOrderMapper payOrderMapper;

    @Bean
    @DependsOn("alipayConfig")
    public PaymentService paymentService(AlipayClient alipayClient, AlipayConfig alipayConfig, JdbcTemplate jdbcTemplate) {
        if (payOrderMapper == null) {
            return null; // 如果映射器不可用，则不创建这个服务
        }
        return new PaymentServiceImpl(alipayClient, alipayConfig, payOrderMapper, jdbcTemplate);
    }
} 